package internetplus_test;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.http.NameValuePair;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import static java.lang.System.out;

/**
 *
 * @author luobo
 */
public class PersonalInfoTest {

    public static void main(String args[]) {
//        out.println(File.separator);
        loginTest();
        modifyUserInfoTest();
//        modifyPasswordTest();
//        modifyProfilePhoto();
    }

    public static void modifyProfilePhoto(){
        String httpUrl = "http://localhost:8080/InternetPlus/personalInfo/modifyUserInfo";
        File file = new File("/Users/luobo/Desktop/rem.png");
        
        if(file.exists()){
//            FileEntity entity = new FileEntity(file,ContentType.DEFAULT_BINARY);
//            MultiPartEntity entity = new MultiPartEntity();
            List<NameValuePair> params = new ArrayList<>();
            BasicNameValuePair photoname = new BasicNameValuePair("photoname",file.getName());
            BasicNameValuePair photoentity = new BasicNameValuePair("photoEntity",file.toString());
            params.add(photoname);
//            InternetRequest.request_postWithCookie(httpUrl, entity);
        }else{
            out.println("文件不存在！");
        }
    }

    /**
     *
     */
    public static void modifyUserInfoTest() {
        String httpUrl = "http://localhost:8080/InternetPlus/personalInfo/modifyUserInfo";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("sign", ".....................");
        jsonObject.put("realname", "王兵兵");
        jsonObject.put("sex", "男");
        jsonObject.put("birthday", new Date(System.currentTimeMillis()).getTime());
        jsonObject.put("exp", "本科");
        jsonObject.put("college", "重庆邮电大学");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);

    }

    /**
     *
     */
    public static void modifyPasswordTest() {
        String httpUrl = "http://localhost:8080/InternetPlus/personalInfo/modifyPassword";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userpass", "0987654321");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithCookie(httpUrl, params);
    }

    /**
     *
     */
    public static void loginTest() {
        String httpUrl = "http://localhost:8080/InternetPlus/login";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", "758172047@qq.com");
        jsonObject.put("password", "1234567890");
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("params", jsonObject.toString()));
        InternetRequest.request_postWithoutCookie(httpUrl, params);
    }
}
